package com.shanghaionstar.user;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.onstar.cn.common.util.CommonUtil;
import com.onstar.cn.framework.annotation.FindViewById;
import com.onstar.cn.framework.mvp.base.core.BaseFragment;
import com.onstar.cn.more.entity.SubscriberDTO;
import com.onstar.cn.more.response.PrepaidCardResponse;
import com.shanghaionstar.R;
import com.shanghaionstar.weight.TopLayout;

/**
 * Created by Mengzhou Gu on 2016/8/4.
 */
public class PayCardActiveSuccessFragment extends BaseFragment {
    private PrePayActivity parentActivity = null;
    @FindViewById
    private TextView tv_car_brank, tv_vin_number, tv_name, tv_phone_number, detail_package_name, tv_card_number_value,
            tv_success_activite;
    @FindViewById
    private TopLayout top_layout;

    private SubscriberDTO accout_obj  = null;
    private String        card_number = null;
    private PrepaidCardResponse activateCardResponse;
    private Bundle              bundle;
    @Override
    public int getLayoutId() {
        return R.layout.user_paycard_active_success_fragment;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        bundle = getArguments();
        parentActivity = (PrePayActivity) getActivity();
        activateCardResponse = (PrepaidCardResponse) bundle.getSerializable("active_obj");
        accout_obj = (SubscriberDTO) bundle.getSerializable("accout_obj");
        card_number = bundle.getString("card_number");

        setPageInfo();

        top_layout.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                parentActivity.finish();
            }
        });
    }

    private void setPageInfo() {
        if (activateCardResponse == null || accout_obj == null) {
            return;
        }
        if (!"".equals(bundle.getString("makeModel")) && bundle.getString("makeModel") != null)
            tv_car_brank.setText(bundle.getString("makeModel"));

        if (!"".equals(bundle.getString("vin")) && bundle.getString("vin") != null) {
            tv_vin_number.setText(bundle.getString("vin"));
        }

        if (!"".equals(accout_obj.getLastName()) && accout_obj.getLastName() != null) {
            tv_name.setText(accout_obj.getLastName() + " " + getString(R.string.xx));
        }

        if (!"".equals(accout_obj.getPhoneNumber()) && accout_obj.getPhoneNumber() != null) {
            tv_phone_number.setText(CommonUtil.replaceEmail(accout_obj.getPhoneNumber().toString(), false));
        } else {
            if (!"".equals(accout_obj.getEmail()) && accout_obj.getEmail() != null) {
                tv_phone_number.setText(CommonUtil.replaceEmail(accout_obj.getEmail(), true));
            }
        }

        if (!"".equals(activateCardResponse.getPackageInfo().getPackageName())
                && activateCardResponse.getPackageInfo().getPackageName() != null) {
            detail_package_name.setText(activateCardResponse.getPackageInfo().getPackageName());
        }

        if (!"".equals(card_number) && card_number != null) {
            tv_card_number_value.setText(card_number);
        }

    }
}
